package com.example.mpandroidchart_all;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;

import com.example.mpandroidchart_all.FragmentChart.FragmentBarChart;
import com.example.mpandroidchart_all.FragmentChart.FragmentCombinedChart;
import com.example.mpandroidchart_all.FragmentChart.FragmentCurveLineChart;
import com.example.mpandroidchart_all.FragmentChart.FragmentLineChart;
import com.example.mpandroidchart_all.FragmentChart.FragmentPieChart;
import com.example.mpandroidchart_all.FragmentChart.FragmentRadarChart;
import com.github.mikephil.charting.charts.LineChart;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private ViewPager viewPager;
    private List<Fragment> list=new ArrayList<>();
    private MyAdapterChart myAdapterChart;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initFragmentChart();

        //可滑动fragment
        viewPager=findViewById(R.id.view_pager);
        myAdapterChart=new MyAdapterChart(getSupportFragmentManager(),0,list);
        viewPager.setAdapter(myAdapterChart);


    }

    /**
     * 初始化各类图表
     */
    private void initFragmentChart(){
        list.add(new FragmentLineChart());//折线图
        list.add(new FragmentPieChart());//饼图
        list.add(new FragmentBarChart());//柱状图
        list.add(new FragmentRadarChart());//雷达图
        list.add(new FragmentCurveLineChart());//曲线
        list.add(new FragmentCombinedChart());//组合图
    }
}
